<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>mytestAdmin</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/config.js" type="application/javascript"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="x-body">
		<form class="layui-form" class="search">
				<div class="layui-input-inline" style="margin-left: -30px;">
					<label class="layui-form-label">执行状态</label>
				</div>
				<div class="layui-input-inline" style="width: 120px;">
					<select id="status" name='status'>
						<option value="ALL">请选择</option>
						<option value="1">正在执行</option>
						<option value="2">执行完成</option>
						<option value="0">待执行</option>
						<option value="-1">准备</option>
						<option value="-2">异常</option>
					</select>
				</div>
				<div class="layui-input-inline">
					<li onclick="search()" class="layui-icon layui-icon-search layui-btn"></li>
				</div>
			</form>
			<script type="text/html" id="toolbarDemo">
				<button class="layui-btn" onclick="fresh()"><i class="layui-icon">ဂ</i></button>
			</script>
			<table class="layui-hide" id="jobList" lay-filter="jobList"></table>

			<!--<table class="layui-hide" id='jobcase'></table>-->

		</div>
		<script type="text/html" id="action">
			<div class="layui-btn-group">
				<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="report">
					测试报告
				</a>
				<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="console">日志</a>
			</div>
		</script>
		<script>
			var table, status
			layui.use('table', function() {
				table = layui.table;
				find();
				//监听行工具事件
				table.on('tool(jobList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'report') {
						if(data.buildnumber == 'no') {
							layer.msg('暂无报告');
						} else {
							window.open(base_url + '/jenkins/'+data.projectid+'/report/' + data.buildnumber)
						}
					} else if(obj.event === 'console') {
						if(data.buildnumber == 'no') {
							layer.msg('暂无输出日志');
						} else {
							window.open(base_url + '/jenkins/'+data.projectid+'/console/' + data.buildnumber)
						}
					} 
				});

			});
		</script>
		<script>
			function add(){
				var ss = parent.layer.open({
					type: 2,
					title: '添加',
					area: ['1000px', '400px'],
					maxmin: true,
					content: ['addjob.html', 'yes'],
					end: function () {
				        location.reload();
				    }
				});
			}
			
			function initparam() {
				status = $("#status").val();
				if (status == "") status = "ALL";
			}
			
			function search() {
				find();
				//执行重载
				table.reload('testtable', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'status': status
					}
				});
			}
			
			function find() {
				initparam();
				table.render({
					elem: '#jobList', headers: {token: username,projectid: projectid},
					url: base_url + '/job/getExcuteLoglist',
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					page: true,
					id: 'testtable',
					toolbar: '#toolbarDemo',
					cols: [
						[{
							field: 'title',
							title: '测试集'
						},  {
							field: 'projectname',
							title: '所属项目'
						}, {
							field: 'starttime',
							title: '开始时间'
						}, {
							field: 'STATUS',
							title: '状态',
						}, {
							fixed: 'right',
							title: '操作',
							toolbar: '#action',
							width: 180
						}]
					]
				});
			}
		</script>
	</body>

</html>